<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>平台用户管理列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">

                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend class="form-title">${organ.title!''}</legend>
                    </fieldset>
                    <div class="layui-card-header">
                        <button class="layui-btn layui-btn-danger" onclick="delAll()">
                            <i class="layui-icon layui-icon-delete"></i>批量删除
                        </button>
                        <button class="layui-btn " onclick="xadmin.open('添加','/user/detail?orgid=${organ.id!''}',600,600)" >
                            <i class="layui-icon layui-icon-add-1"></i>添加
                        </button>
                        <a class="layui-btn layui-btn-small lable-text-center"
                           style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()"
                           title="刷新">
                            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>刷新表格数据</a>
                    </div>


                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" type="post"  action="/user/list">
                        <input type="hidden" name="orgid" value="${user.orgid!''}"/>
                            <div class="layui-input-inline layui-show-xs-block">
                                <input type="text" name="loginname"  value="${user.loginname!''}"  placeholder="登录名" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-show-xs-block">
                                <input type="text" name="name" value="${user.name!''}" placeholder="用户名称" autocomplete="off" class="layui-input" >
                            </div>
                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="states">
                                    <option value="">启用状态(全部)</option>
                                    <#list shiFouStateMap?keys as key>
                                    <option value="${key!''}" <#if user?exists && user.states?exists><#if (user.states)?number == key?number>selected</#if></#if>  > <@mapIntString map=shiFouStateMap key=key/></option>
                                    </#list>
                                </select>
                            </div>
                            <div class="layui-input-inline layui-show-xs-block">
                                <button class="layui-btn"  lay-submit lay-filter="search" >
                                    <i class="layui-icon">&#xe615;</i>搜索
                                </button>
                            </div>

                        </form>
                    </div>

                    <div class="layui-card-body">
                        <table class="layui-table layui-form tableH"   lay-size="sm"  id="tab" >
                            <colgroup>
                                <col width="20">
                                <col>
                                <col>
                                <col>
                                <col>
                                <col width="300">
                                <col width="100">
                            </colgroup>
                            <thead >
                                <tr>
                                    <th>
                                        <input type="checkbox"  name="" lay-skin="primary" lay-filter="checkall">
                                    </th>
                                    <th>登录名</th>
                                    <th>用户名称</th>
                                    <th>排序值</th>
                                    <th>启用状态</th>
                                    <th>所属机构</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            <#list list as user>
                                <tr>
                                    <td class="check">
                                        <input checkid type="checkbox"  name="id" id="id" lay-skin="primary" value="${user.id!''}">
                                    </td>
                                    <td>${user.loginname!''}</td>
                                    <td>${user.name!''}</td>
                                    <td>${user.sorts?c}</td>
                                    <td><input type="checkbox" name="states" value="${user.states!''}" lay-skin="switch" lay-text="启用|未启用" {{ user.states == 1 ? 'checked' : '' }}  <#if user.states?exists && (user.states)?number == 1>checked</#if> disabled/></td>
                                    <td>${organ.title!''}</td>
                                    <td class="td-manage">
                                        <button class="layui-btn layui-btn-xs layui-btn-warm" onclick="xadmin.open('编辑','/user/detail?id=${user.id!''}&orgid=${organ.id!''}',600,600)" >
                                            <i class="layui-icon layui-icon-edit"></i>编辑
                                        </button>

                                        <button class="layui-btn layui-btn-xs layui-btn-normal" onclick="xadmin.open('分配角色','/user/userRoleList?userId=${user.id!''}',600,350)">
                                            <i class="layui-icon layui-icon-component"></i>分配角色
                                        </button>

                                        <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="del(this,'${user.id}')">
                                            <i class="layui-icon layui-icon-delete"></i>删除
                                        </button>
                                    </td>
                                </tr>
                            </#list>
                            </tbody>
                        </table>
                    </div>
                    <!-- 分页条 -->
                    <div id="pager" style="text-align: center;"></div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    layui.use(['laydate', 'form', 'table'], function () {
        var form = layui.form;
        let $ = layui.$;
        // 监听全选
        form.on('checkbox(checkall)', function (data) {
            if (data.elem.checked) {
                $('.check input').prop('checked', true);
            } else {
                $('.check input').prop('checked', false);
            }
            form.render('checkbox');
        });
    });

    // 删除
    function del(obj, id) {
        layui.use('layer',function () {
            let $ = layui.$;
            layer.confirm('确认要删除吗？', function (index) {
                ajaxPost($,"/user/del",{"idArray":id},function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                            location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000}, function(){
                        });
                    }
                });
            });
        });
    }

    function delAll(argument) {
        var ids = [];
        // 获取选中的id
        $('tbody input[checkid]').each(function (index, el) {
            if ($(this).prop('checked')) {
                ids.push($(this).val())
            }
        });
        var idArray = ids.toString();
        if(idArray.length == 0){
            layer.msg('请选择！', {icon: 2, time: 1000}, function(){});
            return false;
        }
        layui.use('layer',function () {
            let $ = layui.$;
            layer.confirm('确认要删除吗？', function (index) {
                ajaxPost($,"/user/del",{"idArray":idArray},function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                            location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000}, function(){
                        });
                    }
                });
            });
        });
    }
</script>
<script>
    layui.use(['laypage', 'layer', 'form'], function(){
        let $ = layui.$;
        var laypage = layui.laypage
            ,form = layui.form
            ,layer = layui.layer;

        laypage.render({
            elem: 'pager'
            ,count: ${(splitPage.totalCount?c)!''}
            ,limit: ${(splitPage.pageSize?c)!''}
            ,curr: ${(splitPage.pageIndex?c)!''}
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            ,jump: function(obj, first){
                //首次不执行
                if(!first){
                    var myform = document.forms[0];
                    // alert("formName:"+myform.id);
                    var pageIndex = document.createElement("input");
                    pageIndex.name="pageIndex";
                    pageIndex.type="hidden";
                    pageIndex.value=obj.curr;
                    myform.appendChild(pageIndex);

                    var pageSize = document.createElement("input");
                    pageSize.name="pageSize";
                    pageSize.type="hidden";
                    pageSize.value=obj.limit;
                    myform.appendChild(pageSize);

                    $("button[lay-submit]:eq(0)").click();
                }
            }
        });
    });
</script>
</html>